//package com.jams.goodox.activity.home;
//
//
//import android.content.Intent;
//import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.support.design.widget.Snackbar;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.util.Log;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//
//import com.jams.goodox.BaseFragment;
//import com.jams.goodox.R;
//import com.jams.goodox.SePref;
//import com.jams.goodox.activity.qa.ClassLearningActivity;
//import com.jams.goodox.adapter.lfadapter.HomeFragmentAdapter;
//import com.jams.goodox.entity.FocusBean;
//import com.jams.goodox.entity.HomeCourse;
//import com.jams.goodox.net.services.LoginService;
//import com.jams.goodox.utils.ToastUtil;
//
//import org.json.JSONArray;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.Bind;
//import butterknife.ButterKnife;
//import me.leefeng.lfrecyclerview.LFRecyclerView;
//import okhttp3.RequestBody;
//import okhttp3.ResponseBody;
//import retrofit2.Call;
//import retrofit2.Callback;
//import retrofit2.Response;
//
///**
// * 主页
// *
// * @author jams
// */
//
//public class HomeFragment extends BaseFragment   {
//
//    private static final String TAG = HomeFragment.class.getSimpleName();
//    View rootView;
//    private static final String ARG_PARAM1 = "param";
//
//    @Bind(R.id.recycleView)
//    RecyclerView recycleView;
//
//    HomeFragmentAdapter adapter;
//    List<HomeCourse> courseList = new ArrayList<>();
//    Intent intent;
//
//    private Intent in;
//    private List<FocusBean> focusBeanList;
//
//    public static HomeFragment newInstance(String param) {
//        HomeFragment fragment = new HomeFragment();
//        Bundle args = new Bundle();
//        args.putString(ARG_PARAM1, param);
//        fragment.setArguments(args);
//        return fragment;
//    }
//
//    @Override
//    public void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//    }
//
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        if (rootView == null) {
//            rootView = inflater.inflate(R.layout.main_layout, container, false);
//            // 初始化页面
//            ButterKnife.bind(this, rootView);
//        }
//        ButterKnife.bind(this, rootView);
//        init();
//        return rootView;
//    }
//
//    private void init(){
//        //页面滚动时停止banner滚动
////        courseList.add(new HomeCourse(3,"111"));//添加轮播图
//        adapter = new HomeFragmentAdapter(getContext(), courseList);
//
////        recycleView.setLoadMore(false);
////        recycleView.setRefresh(true);
////        //recycleView.setNoDateShow();
////        recycleView.setAutoLoadMore(false);
////        recycleView.setOnItemClickListener(this);
////        recycleView.setLFRecyclerViewListener(this);
////        recycleView.setScrollChangeListener(this);
////        recycleView.setItemAnimator(new DefaultItemAnimator());
////        recycleView.setFootText("---我是有底线的---");
//
//        recycleView.setLayoutManager(new LinearLayoutManager(getContext()));
//
//        recycleView.setAdapter(adapter);
//
//        adapter.setOnItemClickListener(new HomeFragmentAdapter.OnItemClickListener() {
//            @Override
//            public void OnItemClick( int position) {
//                if(SePref.isLogin()){
//                    Log.d(TAG," == " + courseList.get(position).toString());
//                    intent = new Intent(getActivity(),ClassLearningActivity.class);
//                    intent.putExtra("courseId",courseList.get(position).getCourseId());
//                    intent.putExtra("imagePath",courseList.get(position).getImgPath());
//                    intent.putExtra("nickName",courseList.get(position).getNickName());
//                    //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    startActivity(intent);
//                }else {
//                    if(courseList.get(position).getPrice() <= 0){
//                        intent = new Intent(getActivity(),ClassLearningActivity.class);
//                        intent.putExtra("courseId",courseList.get(position).getCourseId());
//                        intent.putExtra("imagePath",courseList.get(position).getImgPath());
//                        intent.putExtra("nickName",courseList.get(position).getNickName());
//                        startActivity(intent);
//                    }else {
//                        ToastUtil.show("请登录后查看");
//                    }
////                    Snackbar.make(recycleView, "请登录查看", Snackbar.LENGTH_LONG).show();
//                }
//            }
//        });
//
////        getHomeInfo();
//    }
//
//
//    private void getHomeInfo(){
//        clearMap();
//        params.put("requestData", "{}");
//
//        String strEntity = gson.toJson(params);
//        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"),strEntity);
//
//        showLoading();
//
//        createCallService(LoginService.class).homeInfo(body).enqueue(new Callback<ResponseBody>() {
//            @Override
//            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//                misLoading();
//                try {
//                    String data = response.body().string();
//                    Log.d(TAG, "home data = " + data);
//                    JSONObject jsonObject = new JSONObject(data);
//
//                    if(200 == jsonObject.getInt("code")){
//                        JSONObject object = new JSONObject(jsonObject.getString("responseData"));
//                        Log.d(TAG, "responseData = " + object.toString());
//
//                        JSONArray freeAray = object.getJSONArray("freeCourse");
//                        if(null != freeAray && freeAray.length() > 0){
//                            courseList.add(new HomeCourse(0,"免费专区"));
//                            for (int i = 0; i < freeAray.length(); i++){
//                                JSONObject childObj = freeAray.getJSONObject(i);
//                                HomeCourse freeCourse = new HomeCourse();
//                                freeCourse.setMemberId(childObj.getInt("memberId"));
//                                freeCourse.setCourseId(childObj.getInt("courseId"));
//                                freeCourse.setDescr(childObj.getString("descr"));
//                                freeCourse.setFree(true);
//                                freeCourse.setType(1);
//                                freeCourse.setImgPath(childObj.getString("imgPath"));
//                                freeCourse.setNickName(childObj.getString("nickName"));
//                                freeCourse.setPrice(childObj.getInt("price"));
//                                freeCourse.setRadioLink(childObj.getString("radioLink"));
//                                freeCourse.setTitle(childObj.getString("title"));
//                                freeCourse.setTimeLength(childObj.getInt("timeLength"));
//                                freeCourse.setTranslateState(childObj.getInt("translateState"));
//
//                                courseList.add(freeCourse);
//                            }
//                        }
//
//                        JSONArray greatArray = object.getJSONArray("greatCourse");
//                        if(null != greatArray && greatArray.length() > 0){
//                            courseList.add(new HomeCourse(0,"精品课程"));
//                            for (int i = 0; i < greatArray.length(); i++){
//                                JSONObject childObj2 = greatArray.getJSONObject(i);
//                                HomeCourse greatCourse = new HomeCourse();
//                                greatCourse.setMemberId(childObj2.getInt("memberId"));
//                                greatCourse.setCourseId(childObj2.getInt("courseId"));
//                                greatCourse.setDescr(childObj2.getString("descr"));
//                                greatCourse.setFree(false);
//                                greatCourse.setType(2);
//                                greatCourse.setImgPath(childObj2.getString("imgPath"));
//                                greatCourse.setNickName(childObj2.getString("nickName"));
//                                greatCourse.setPrice(childObj2.getInt("price"));
//                                greatCourse.setRadioLink(childObj2.getString("radioLink"));
//                                greatCourse.setTitle(childObj2.getString("title"));
//                                greatCourse.setTimeLength(childObj2.getInt("timeLength"));
//                                greatCourse.setTranslateState(childObj2.getInt("translateState"));
//
//                                courseList.add(greatCourse);
//                            }
//                        }
//
//                        adapter.notifyDataSetChanged();
//
//                    }
//                } catch (JSONException e1) {
//                    e1.printStackTrace();
//                }  catch ( Exception e) {
//                    ToastUtil.show("Exception:" + e.getMessage());
//                }
//
//            }
//
//            @Override
//            public void onFailure(Call<ResponseBody> call, Throwable t) {
//                misLoading();
//                ToastUtil.show("failure:" + t.getMessage());
//            }
//        });
//    }
//
//    @Override
//    public void onDestroyView() {
//        super.onDestroyView();
//        ButterKnife.unbind(this);
//    }
//
//
//    @Override
//    public void onResume() {
//        super.onResume();
//        courseList.clear();
//        courseList.add(new HomeCourse(3,"111"));//添加轮播图
//        getHomeInfo();
//    }
//
//}
